package cn.tdeu.spring.life;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

@Component
public class Life {
    private String name;

    public Life() {
        System.out.println("1.生命周期创建阶段");
    }

    @Value("世界那么大，我想去看看")
    public void setName(String name) {
        this.name = name;
        System.out.println("2.set方法属性赋值");
    }
    @PostConstruct
    public void init() {
        System.out.println("3.生命周期初始化阶段");
    }

    @PreDestroy
    public void destroy() {
        System.out.println("5.生命周期销毁阶段");
    }

    @Override
    public String toString() {
        return "Life{" +
                "name='" + name + '\'' +
                '}';
    }
}
